"""导包"""
import pymysql
"""连接数据库"""
conn = pymysql.connect(host="127.0.0.1",
                       port=3306,
                       user="root",
                       password="root",
                       database="books",
                       charset="utf8")
"""创建游标"""
cursor = conn.cursor()
"""创建sql语句"""
sql = "select * from t_book;"
# 执行sql
cursor.execute(sql)
# 查询所有结果
print(cursor.fetchall())
"""查询受影响的行数"""
print(cursor.rowcount)
"""查询目前游标处在哪个位置"""
print(cursor.rownumber)
"""将游标移到零"""
cursor.rownumber=0
"""显示目前游标的位置"""
print(cursor.rownumber)
"""显示查询出的第一个结果"""
print(cursor.fetchone())
"""将游标位置回到零"""
cursor.rownumber=0
"""查找当前游标的位置"""
print(cursor.rownumber)
"""指定行查找数据"""
print(cursor.fetchmany(3))
"""关闭游标"""
cursor.close()
"""关闭连接"""
conn.close()
